﻿// MIT License
//
// Copyright (c) 2021-present zuohuaijun, Daming Co.,Ltd and Contributors
//
// 电话/微信：18020030720 QQ群1：87333204 QQ群2：252381476

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ToolCloud.Core.Entity;
using ToolCloud.Core.Service.Access.Dto;

namespace ToolCloud.Core.Service.Access;

[ApiDescriptionSettings(Order = 450)]
public class AccessStatisticService : IDynamicApiController, ITransient
{
    private readonly SqlSugarRepository<AccessStatistic> _accessStatisticRep;

    public AccessStatisticService(SqlSugarRepository<AccessStatistic> accessStatisticRep)
    {
        _accessStatisticRep = accessStatisticRep;
    }

    /// <summary>
    /// 获取访问数量
    /// </summary>
    /// <returns></returns>
    [AllowAnonymous]
    [DisplayName("获取访问数量")]
    public async Task<List<AccessOutput>> GetAccessList(AccessInput input)
    {
        var date = input.Date.ToString("yyyy-MM");
        if (input.DateType == Dto.DateType.Year)
        {
            date = input.Date.ToString("yyyy");
        }
        var lsit = await _accessStatisticRep.AsQueryable().Where(o => o.AccessDate.StartsWith(date)).ToListAsync();

        return lsit.Adapt<List<AccessOutput>>();
    }
}
